<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once dirname(__FILE__)."/CharacterManager.class.php";
require_once dirname(__FILE__)."/Localization.class.php";
require_once dirname(__FILE__)."/LocaleContainer.class.php";

class Subscription
{
	private $id;
	private $sid;
	private $nickname;
	private $name;
	private $password;
	private $creation_date;
	private $locale;
	private $times_uploaded;
	private $nb_items_updated;
	private $nb_spells_updated;
	private $nb_reagents_updated;
	private $last_upload;
	
	private $owned_characters = null;
	
	static private $localization;
	static private $locale_container;
	
	function Subscription($t)
	{
		if ( empty(self::$locale_container) )
		{
			self::$locale_container = LocaleContainer::GetInstance();
			self::$localization = Localization::GetInstance();
		}
		
		$this->id = $t['account_id'];
		$this->sid = $t['account_sid'];
		$this->nickname = $t['account_nickname'];
		$this->name = $t['account_name'];
		$this->password = $t['account_password'];
		$this->creation_date = $t['account_creation'];
		$this->locale = $t['account_locale'];
		$this->times_uploaded = $t['account_times_uploaded'];
		$this->nb_items_updated = $t['account_nb_items_updated'];
		$this->nb_spells_updated = $t['account_nb_spells_updated'];
		$this->nb_reagents_updated = $t['account_nb_reagents_updated'];
		$this->last_upload = $t['account_last_upload'];
	}
	
	function GetId()
	{
		return $this->id;
	}
	
	function GetSid()
	{
		return $this->sid;
	}
	
	function GetNickName()
	{
		return $this->nickname;
	}
	
	function GetName()
	{
		return $this->name;
	}
	
	function GetPassword()
	{
		return $this->password;
	}
	
	function GetLocale()
	{
		return $this->locale;
	}
	
	function GetLocaleLiteral()
	{
		return self::$locale_container->GetLocale($this->locale)->GetName();
	}
	
	function GetCreationDate()
	{
		return date("d/m/Y", strtotime($this->creation_date));
	}
	
	function GetTimesUploaded()
	{
		return $this->times_uploaded;
	}
	
	function GetNbItemsUpdated()
	{
		return $this->nb_items_updated;
	}
	
	function GetNbSpellsUpdated()
	{
		return $this->nb_spells_updated;
	}
	
	function GetNbReagentsUpdated()
	{
		return $this->nb_reagents_updated;
	}
	
	function GetLastUpload()
	{
		if ( strtotime($this->last_upload) - strtotime(0) == 0 )
		{
			return self::$localization->Get('no upload recorded');
		}
		else
		{
			return date("d/m/Y, H:i:s", strtotime($this->last_upload));
		}
	}
	
	function SetLocale($locale)
	{
		$this->locale = $locale;
	}
	
	function SetPassword($new_pass)
	{
		$this->password = md5($new_pass);
	}
	
	function SetNickName($new_nickname)
	{
		$this->nickname = $new_nickname;
	}
	
	function SetSid($sid)
	{
		$this->sid = $sid;
	}
	
	function GetOwnedCharactersWithTradeskills()
	{
		if ($this->owned_characters == null)
		{
			$character_manager = CharacterManager::GetInstance();
			
			$this->owned_characters = $character_manager->GetCharactersAndProfessionsByAccountId($this->id);
		}
		
		return $this->owned_characters;
	}
}

?>